home *** CD-ROM | disk | FTP | other *** search
- Path: chronicle.mti.sgi.com!news
- From: austern@isolde.mti.sgi.com (Matt Austern)
- Newsgroups: comp.lang.c++
- Subject: Re: Will JAVA kill C++?
- Date: 14 Mar 1996 04:54:26 GMT
- Organization: SGI
- Message-ID: <AUSTERN.96Mar13205426@isolde.mti.sgi.com>
- References: <313E44EA.14D110C0@netcom.com> <4hp18v$3di@frodo.smartlink.net>
- <4hqkfk$20j@galaxy.ucr.edu>
- Reply-To: austern@mti.sgi.com
- NNTP-Posting-Host: isolde.mti.sgi.com
- In-reply-to: thp@cs.ucr.edu's message of 9 Mar 1996 00:47:48 GMT
-
- In article <4hqkfk$20j@galaxy.ucr.edu> thp@cs.ucr.edu (Tom Payne) writes:
-
- > : In C++, or Fortran, or Eiffel, you can have an array of complex
- > : numbers. In Java, though, you can't: you can have something that
- > : looks like an array of complex numbers, but internally it's really an
- > : array of pointers to complex numbers. You have to pay a space penalty
- > : to store those pointers, and a time penalty to do the dereferencing on
- > : every element, and the optimizer will have to generate code on
- > : assumption that two array elements might point to the same object.
- >
- > Are these references resettable? If not, how can they be made to
- > collide like that? In fact, if they are not resettable, is there
- > any reason that the extra level of indirection couldn't be
- > optimized away?
-
- public class complex
- {
- public complex(double re, double im)
- {
- Re = re;
- Im = im;
- }
-
- public double Re;
- public double Im;
- }
-
-
- class F
- {
- static public void f()
- {
- complex[] A = new complex[3];
- A[0] = new complex(1, 1);
- A[1] = new complex(0, 1);
- A[2] = A[0]; // A[0] and A[2] point to the same object.
-
- complex[] B = new complex[1];
- B[0] = A[1]; // B[0] and A[1] now point to the same object.
-
- G.g(A);
- }
- }
-
- class G
- {
- static public void g(complex[] array)
- {
- array[0].Re = 0; // The compiler can't assume that array[0] is
- // the only element of array to have changed.
- // ...
- }
- }
-
-
- I don't see that Java solves any aliasing problems. It does have
- pointers, and the fact of pointer semantics is very clearly visible to
- the user in many different ways. I don't see how you could optimize
- away anything so fundamental and pervasive; if you're able to write an
- optimizer that can perform heroics like that, then dealing with the
- aliasing problems in C and C++ would be trivial.
-
- Just to keep this slightly germane to C++, the right way to avoid
- aliasing problems is to use the valarray template. You should ask
- your compiler vendor to implement valarrys, and to do it right.
- --
- Matt Austern
- SGI: MTI Compilers Group
- austern@isolde.mti.sgi.com
-